package com.ckzp.jfinal.base;

import cn.hutool.core.io.FileUtil;
import com.ckzp.core.ConfigUtil;
import com.ckzp.core.util.ClientUtil;
import com.ckzp.core.validate.FileValidate;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;

import java.io.File;

/**
 * Created by 51594 on 2022/11/10.
 */
public class JfinalCheck {

    /**
     * 检查配置文件
     */
    public static void checkConfig() {
        System.out.println("-----------------------------START---------------------------------------");
        String node = ClientUtil.getWebNode();
        String classpath = ConfigUtil.getWebInfoPath();
        //ehcache的配置文件
        if (!new File(classpath + "/classes/ehcache.xml").exists()) {
            System.out.println("/WEB-INF/classes/ehcache.xml not exit");
        }
        //log4j.properties
        if (!new File(classpath + "/classes/log4j.properties").exists()) {
            System.out.println("/WEB-INF/classes/log4j.properties not exit");
        }

        if (ConfigUtil.isWindows()) {
            //win_web.properties
            String win_path = classpath + "/classes/win_web.properties";
            win_path = FileValidate.validatePath((win_path));
            if (!FileUtil.exist(win_path)) {
                System.out.println("/WEB-INF/classes/win_web.properties not exit");
            }
        } else if (node != null && node.indexOf("node") > -1) {
            String nodepath = classpath + "/classes/linux_" + node + ".properties";
            nodepath = FileValidate.validatePath((nodepath));
            if (!FileUtil.exist(nodepath)) {
                System.out.println("/WEB-INF/classes/linux_" + node + ".properties not exit");
            }
        } else {
            String linuxpath = classpath + "/classes/linux_web.properties";
            linuxpath = FileValidate.validatePath((linuxpath));
            if (!FileUtil.exist(linuxpath)) {
                System.out.println("/WEB-INF/classes/linux_web.properties not exit");
            }
        }
    }
}
